<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('出库明细报表')" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.js" type="text/javascript"></script>
<body id="colTb" style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">渠道名称</label>
                        <div class="layui-input-inline">
                            <select lay-ignore="lay-ignore" id='ajax_qdmc' style="width: 193px"></select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="cjsj" />
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button"> 搜索 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #40AFFE">重置</button>
                    </div>
                    <input type="hidden" id="cjsj_start" name="cjsj_start">
                    <input type="hidden" id="cjsj_end" name="cjsj_end">
                </form>
                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal out-put">
                        <i class="layui-icon">&#x1005;</i> 导出
                    </a>
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body" >
                    <div class="pro">
                        <table id="dataTable"class="table text-nowrap" width="100%">
                        </table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<script>
    //    //	回车查询
    //    document.onkeydown = function(event) {
    //        e = event ? event : (window.event ? window.event : null);
    //        if (e.keyCode == 13) {
    //            //执行的方法
    //            $('#search_button').click();
    //        }
    //    };
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'form'], function () {
        var myColumns = [];
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        //创建时间开始
        var cjsj_start;
        var cjsj_end;
        laydate.render({
            elem: '#cjsj',
            type: 'date',
            range:'~',
            done: function(value, date, endDate){
                if(value!=null && value !=""){
                    cjsj_start=value.toString().substring(0,value.toString().indexOf("~"));
                    cjsj_end=value.toString().substring(value.toString().indexOf("~")+1);
                    $("#cjsj_start").val(Date.parse(new Date(cjsj_start)));
                    $("#cjsj_end").val(Date.parse(new Date(cjsj_end)));
                }else {
                    $("#cjsj_start").val("");
                    $("#cjsj_end").val("");
                }


                /*  alert(Date.parse(new Date($("#cjsj_start").val())));
                 alert("2018-8-1:"+Date.parse(new Date("2018-8-1")));
                 alert("2018-08-01:"+Date.parse(new Date("2018-08-01")));

                 console.log(value); //得到日期生成的值，如：2017-08-18
                 console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                 console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。*/
            }
        });
        // 查询渠道名称
        var two;
        var scc
        $('#ajax_qdmc').select2({
            ajax: {
                url: '/zxsswms/Outstock/getDdmc',
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        mc: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr= [];
                    scc = data;
                    console.log('data', data);
                    if(data){
                        for (var i=0;i<data.length;i++){
                            two = data[i].id.toString() + ',' + data[i].mc.toString();
                            arr.push({id:two,text:data[i].mc});
//                            console.log('data.ddqdid', data[i].id);
//                            console.log('data.ddqdmc', data[i].mc);
                        }
                    }
//                    console.log('3333333', two);
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询包装',
            allowClear: true
        });

        window.operateEvent ={
            "click .layui-btn-primary":function (e, value, row, index) {
                alert(row.mc);
                console.log('eeee', e);
                console.log('value', value);
                console.log('row', row);
                console.log('index', index);
            }
        },
            myColumns = getColumns();
//        var $table = zzpUtils.table({
//            elem: '#dataTable',
//            isApi: true,
//            pagination: true,
//            autoWidth: false,
//            scrollX: true,
//            data: {},
//            columns: myColumns,
//        });
        //
        // 原生请求
//        $('#search_button').click(function () {
//            console.log(1);
//            var arrdata = [];
//            strs= $('#ajax_qdmc').val().split(",");
//            $.ajax({
//                type: 'post',
//                url: '/zxsswms/Outstock/list',
//                contentType: "application/json",
//                async: true,
//                data: JSON.stringify({
//                    ddqdid: strs[0],
//                    ddqdmc: strs[1],
//                    cjsj_start :$('#cjsj_start').val(),
//                    cjsj_end: $('#cjsj_end').val(),
//                    page: 1,
//                    rows: 10,
//                }),
//                success: function (res) {
//                    console.log('res', res.contentList);
//                    $table.bootstrapTable("append",res.contentList);
//                }
//
//            });
////            console.log('strsstrsstrs', strs);
//        });
        var $table = zzpUtils.table({
            elem: '#dataTable',
            isApi: true,
            pagination: true,
            autoWidth: false,
            scrollX: true,
            url: '/Outstock/list', // 获取数据的地址
            columns: myColumns,
            queryParams: function () {//查询条件
                return {}
//                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            }

        });
        var strs;
        $('#search_button').click(function () {
            console.log('搜索');
//           var ddqd = $('#ajax_qdmc').val();
//            console.log('订单渠道',ddqd);
//            console.log('shijian',$('#cjsj_start').val());
//            console.log('shijianend',$('#cjsj_end').val());
            var obj = $('#ajax_qdmc').val();
            console.log('obj', obj);
            if (obj === null) {
                strs = '','';
            } else {
              strs = obj.split(',');
            }
            console.log('strs',$('#ajax_qdmc').val());

            $('#dataTable').bootstrapTable('refresh',{
                query:{
                    ddqdid: strs[0],
                    ddqdmc: strs[1],
                    cjsj_start :$('#cjsj_start').val(),
                    cjsj_end: $('#cjsj_end').val(),
                    page: 1,
                    rows: 10,
                },
            });
        });
        /*$(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#dataTable");
        })*/
        function getColumns() {
            var ajaxdata = [];
            // 加载动态表格
            $.ajax({
                url: '/zxsswms/Outstock/listHeader',
                type: 'POST',
                dataType: "json",
//                data: {state: $('#state').val()},
                async: false,
                success: function (returnValue) {
                    ajaxdata.push({"field": '',
                        "checkbox": true,
                    });
                    // 异步获取要动态生成的列
                    var arr = returnValue.column;
                    console.log('arrarrarr', arr)
                    $.each(arr, function (i, item) {
                        ajaxdata.push({
                            "field": item.prop,
                            "title": item.label,
                            "hide": true,
                            "align": 'center',
                            "valign": 'middle'
                        });
                    });
                    console.log(ajaxdata);
                }
            });
            return ajaxdata;
        }

        /*顶部按钮导出 */
        $(".out-put").on('click', function () {
            var arr=[];
            var $rows = $table.bootstrapTable('getSelections');
            console.log('$rows',$rows);
            if ($rows.length >0) {
                arr = $.map($rows, function (row) {
                    return row.cpid;
                })
            }

            /*
             * 以下是将ids和对象拼接在一起
             * */
            var obj = [];
            console.log('arr',arr);
            for(var i=0;i<arr.length;i++) {
                var person = {};
                person[i] = arr[i];
                obj.push(person);
            }
            var ddqd = $('#ajax_qdmc').val().split(',');
            console.log('strvaue', ddqd);
            var str=zzpUtils.getFormJson($("#searchForm"));
            var object2 = Object.assign(str, {ddqdid: ddqd[0]}, {ddqdmc: ddqd[1]},{page:1},{rows:10},{ids: arr});
            /*将条件查询和ids传到后台*/
//            xhr.send();
            zzpUtils.outputXslx({
                url:"/Outstock/OutstockExport",
                data:JSON.stringify(object2)
            });
        })//导出结束

    })



</script>
</html>